# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-console
pkgver=1.16.2
pkgrel=2
pkgdesc='Beautiful logging for Ruby'
arch=(any)
url='https://github.com/socketry/console'
license=(MIT)
depends=(ruby-fiber-local)
checkdepends=(ruby-bake ruby-bake-test ruby-bake-test-external ruby-covered ruby-sus)
options=(!emptydirs)
source=(https://github.com/socketry/console/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('8df6857a79b7c75325947c0b273c1c38511e9f36806437b8b8d4213594696421')

prepare() {
  cd console-$pkgver
  sed -r -e 's|~>|>=|g' -e '/signing_key/d' -i console.gemspec
  sed -i '/bake-gem/d;/bake-modernize/d;/bake-github-pages/d;/utopia-project/d' gems.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd console-$pkgver
  gem build console.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    console-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd console-$pkgver
  GEM_HOME="tmp_install/$_gemdir" bake test
}

package() {
  cd console-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
